﻿/*
 * 版 本 v1.0
 * Copyright (c) 2013-2018 广州市同慧信息科技有限公司
 * 创建人：ftquan
 * 日 期：2017.04.18
 * 描 述：岗位选择
 */
var dfopid = request('dfopid');
var selectValue = request('selectValue');

var companyId = request('companyId');

var acceptClick;
var bootstrap = function ($, learun) {
    "use strict";
    var postitem = {value: '', text: ''};

    var page = {
        init: function () {
            page.bind();
            page.initData();
        },
        bind: function () {
            $('#form_company_list').lrtree({
                url: config.base_server() + 'companys/tree?access_token=' + config.getToken().access_token,
                param: {parentId: '0',companyId: companyId},
                nodeClick: function (item) {
                    $('#form_post_list').lrtreeSet('refresh', {
                        url: config.base_server() + 'posts/tree?access_token=' + config.getToken().access_token,
                        param: {companyId: item.id}
                    });
                }
            });
            if(!!companyId) {
                $('#form_company_list').lrtreeSet('setValue', companyId);
            } else {
                $('#form_company_list').lrtreeSet('checkFirst');
            }

            $('#form_post_list').lrtree({
                nodeClick: function (item) {
                    postitem.value = item.id;
                    postitem.text = item.text;
                }
            });


            $('.form-post-search>input').on("keypress", function (e) {
                if (event.keyCode == "13") {
                    var keyword = $(this).val();
                    $('#form_post_list').lrtreeSet('search', {keyword: keyword});

                }
            });
        },
        initData: function () {
            if (!!selectValue && selectValue != "0") {
                learun.httpAsync('GET', config.base_server() + 'posts/' + selectValue + '&access_token=' + config.getToken().access_token, null, function (data) {
                    if (!!data) {
                        $('#form_company_list').lrtreeSet('setValue', data.companyId);
                        $('#form_post_list').lrtreeSet('setValue', data.id);
                    }
                });
            }
        }
    };
    // 保存数据
    acceptClick = function (callBack) {
        callBack(postitem, dfopid);
        return true;
    };
    page.init();
}